﻿using System;
using System.Drawing;

namespace TienLen
{
    /// <summary>
    /// Special Windows Form timer for card animation.
    /// </summary>
    public class AnimTimer : System.Windows.Forms.Timer
    {
        private int elasped = 0;
        private int animTicks = 0;
        private Point sizeInc;

        /// <summary>
        /// Number of times the timer has ticked.
        /// </summary>
        public int Elasped
        {
            get { return elasped; }
            set { elasped = value; }
        }

        /// <summary>
        /// The number of ticks required to finish the animation
        /// </summary>
        public int TicksNeeded
        {
            get { return animTicks; }
            set { animTicks = value; }
        }

        /// <summary>
        /// How much the card should move in every tick.
        /// </summary>
        public Point SizeIncrement
        {
            get { return sizeInc; }
            set { sizeInc = value; }
        }

        public AnimTimer(Point diff, int animTag)
        {
            this.Tick += new EventHandler(delegate(object obj, EventArgs e)
                { elasped++; });

            if (diff != new Point())
            {
                sizeInc = new Point(diff.X / 9, diff.Y / 9);
                animTicks = (int)Math.Abs((Math.Abs((float)diff.X) + Math.Abs((float)diff.Y)) /
                    (Math.Abs((float)sizeInc.X) + Math.Abs((float)sizeInc.Y)));
            }

            this.Tag = animTag;
        }
    }
}
